# +----------------------------------------------------------------------
# | ChatWork
# +----------------------------------------------------------------------
# | 这不是一个自由软件,您只能在不用于商业目的的前提下对程序代码进行修改和使用。
# | 任何企业和个人不允许对程序代码以任何形式任何目的再发布,商业使用请获取授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from fastapi import Query
from pydantic import BaseModel, Field


class RobotPublishSearchIn(BaseModel):
    """ 发布搜索参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    scene: str = Query(..., description="发布场景: [web,api]")
    bot: str = Query(..., description="智能体编号")


class RobotPublishAddIn(BaseModel):
    """ 发布新增参数 """
    bot: str = Field(..., min_length=1, max_length=32, description="智能体Code")
    name: str = Field(..., min_length=1, max_length=32, description="发布名称")
    scene: str = Field(..., min_length=1, pattern=r"^(web|api)$", description="场景: [web,api]")
    api_secret: str = Field(default="", max_length=32, description="通道密码")
    max_points: int = Field(default=0, ge=0, description="最大额度")
    rpm_limit: int = Field(default=0, ge=0, description="每分钟限制")
    expire_time: int = Field(default=0, description="失效时间")

    @classmethod
    def messages(cls):
        return {
            "name.min_length": "发布名称不能为空值",
            "name.max_length": "发布名称不能超出32个字符",
            "scene.api_secret": "发布场景选择异常: [web,api]",
            "api_secret.max_length": "通道密码不能超出32个字符"
        }

    class Config:
        json_schema_extra = {
            "example": {
                "bot": "HCxiS50f0d4nd",
                "scene": "window",
                "name": "体验窗口",
                "api_secret": "",
                "max_points": 0,
                "rpm_limit": 0,
                "expire_time": 0
            }
        }


class RobotPublishEditIn(BaseModel):
    """ 发布编辑数 """
    id: int = Field(..., gt=0, description="ID")
    name: str = Field(..., min_length=1, max_length=32, description="发布名称")
    api_secret: str = Field(default="", max_length=32, description="通道密码")
    max_points: int = Field(default=0, ge=0, description="最大额度")
    rpm_limit: int = Field(default=0, ge=0, description="每分支限制")
    expire_time: int = Field(default=0, ge=0, description="失效时间")

    @classmethod
    def messages(cls):
        return {
            "name.min_length": "发布名称不能为空值",
            "name.max_length": "发布名称不能超出32个字符",
            "api_secret.max_length": "通道密码不能超出32个字符"
        }

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "name": "体验窗口",
                "api_secret": "",
                "max_points": 0,
                "expire_time": 0
            }
        }


class RobotPublishDeleteIn(BaseModel):
    """ 发布删除参数 """
    id: int = Field(..., gt=0, description="ID")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1
            }
        }


"""--------------- Separator ---------------"""


class RobotPublishListVo(BaseModel):
    """ 发布列表VO """
    id: int = Field(description="ID")
    scene: str = Field(description="发布场景")
    name: str = Field(description="渠道名称")
    api_key: str = Field(description="接口密钥")
    api_secret: str = Field(description="接口密码")
    max_points: int = Field(description="最大额度")
    use_points: int = Field(description="消耗额度")
    call_count: int = Field(description="调用次数")
    rpm_limit: int = Field(description="每分钟限制")
    is_expire: bool = Field(description="是否已失效")
    last_time: str = Field(description="最后使用时间")
    expire_time: str = Field(description="过期时间")
    create_time: str = Field(description="创建时间")
    update_time: str = Field(description="更新时间")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "scene": "window",
                "name": "体验窗口",
                "api_key": "wa-bf59f9fd0b7b6ae79b0fdd27e15e5bbb",
                "api_secret": "",
                "max_points": 20,
                "use_points": 5,
                "call_count": 0,
                "rpm_limit": 0,
                "is_expire": False,
                "last_time": "-",
                "expire_time": "-",
                "create_time": "2024-10-28 14:18:20",
                "update_time": "2024-10-28 14:18:20"
            }
        }
